package com.swhysc.information.common.model;

import java.util.List;

/**
 * @Author zmq
 * @Date 2023/8/30 16:50
 * @Description
 */
public class GridView<T> {
    private List<T> rows;
    private List<T> deptcodes;
    private long total;
    private int pageSize;
    private int pageNumber;
    private int totalPages;
    private int records;
    public List<T> getRows() {
        return this.rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }
    public List<T> getDeptcodes() {
        return deptcodes;
    }

    public void setDeptcodes(List<T> deptcodes) {
        this.deptcodes = deptcodes;
    }
    public long getTotal() {
        return this.total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getRecords() {
        return records;
    }

    public void setRecords(int records) {
        this.records = records;
    }

    public GridView() {}

    public GridView(int pageSize, int records, List<T> rows) {
        this.pageSize = pageSize;
        this.records = records;
        this.rows = rows;
    }

    public GridView(List<T> rows, long total) {
        setRows(rows);
        setTotal(total);
    }

    public GridView(List<T> rows, long total, int pageSize, int PageNumber) {
        setRows(rows);
        setTotal(total);
        setPageSize(pageSize);
        setPageNumber(PageNumber);
        int totalPages = (int) (total / pageSize);
        if (total % pageSize > 0) {
            setTotalPages(totalPages + 1);
        } else {
            setTotalPages(totalPages);
        }
    }
    //主要针对的是datagrid的分页，datagrid的总页数不是totalPage,所以重写构造方法
    public GridView(List<T> rows,long total, int records,int pageSize, int PageNumber) {
        setRows(rows);
        setRecords(records);
        setPageSize(pageSize);
        setPageNumber(PageNumber);
        int totalPages = (int)(total / pageSize);
        if (total % pageSize > 0) {
            setTotal(totalPages + 1);
        } else {
            setTotal(totalPages);
        }
    }
    //主要针对的是分页时需要再传入一个集合参数，所以重写构造方法
    public GridView(List<T> rows, List<T> deptcodes, long total, int pageSize, int PageNumber) {
        setRows(rows);
        setDeptcodes(deptcodes);
        setTotal(total);
        setPageSize(pageSize);
        setPageNumber(PageNumber);
        int totalPages = (int) (total / pageSize);
        if (total % pageSize > 0) {
            setTotalPages(totalPages + 1);
        } else {
            setTotalPages(totalPages);
        }
    }
}
